package com.chenyuxin.ilp;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.jwt.JWTUtil;
import com.chenyuxin.ilp.mapper.user.UserMapper;
import com.chenyuxin.ilp.model.entity.user.User;
import com.chenyuxin.ilp.model.vo.user.UserLoginVo;
import com.chenyuxin.ilp.util.JwtUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.HashMap;
import java.util.Map;

@SpringBootTest
public class TokenGenerateTest {
    @Autowired
    private UserMapper userMapper;
    @Test
    void createToken() {
        User user = userMapper.selectById("b25139a3a777430d95635440749ccc45");
        UserLoginVo userLoginVo = BeanUtil.copyProperties(user, UserLoginVo.class);
        Map<String, Object> claims = BeanUtil.beanToMap(userLoginVo);
        long expireTime = System.currentTimeMillis() + 7 * 24 * 60 * 60 * 1000;
        String s = JwtUtils.generateToken(claims, expireTime);
        System.out.println(s);

    }
}